package com.example.a2207_zh.adapter

import android.widget.ImageView
import androidx.core.view.isVisible
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.a2207_zh.R
import com.example.a2207_zh.entity.VideoEntity
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

class VideoAdapter(list: MutableList<VideoEntity>):BaseMultiItemQuickAdapter<VideoEntity,BaseViewHolder>(list) {
    init {
        addItemType(0, R.layout.item_video_normal)
        addItemType(1,R.layout.item_video_live)
        addItemType(2,R.layout.item_video_full)
        addItemType(5,R.layout.item_video_normal)
    }
    override fun convert(holder: BaseViewHolder, item: VideoEntity) {
        when(holder.itemViewType){
            0,2,5->{

               val gsy =  holder.getView<StandardGSYVideoPlayer>(R.id.gsy)
                gsy.setUp(item.videopath,true,"")
                gsy.startPlayLogic()
                gsy.backButton.isVisible = false

                Glide.with(context).load(item.headpath).into(holder.getView(R.id.iv_user))
                //显示正确的点赞状态
                val ivLove = holder.getView<ImageView>(R.id.iv_love)
                if(item.dianzan==1){
                    ivLove.setImageResource(R.drawable.baseline_favorite_24)
                }else{
                    ivLove.setImageResource(R.drawable.baseline_favorite_border_24)
                }
            }
            1->{
                val gsy =  holder.getView<StandardGSYVideoPlayer>(R.id.gsy)
                gsy.setUp(item.videopath,true,"")
                gsy.startPlayLogic()
                gsy.backButton.isVisible = false
            }
        }
    }
}